package org.example.controller;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class EmailController {

    @Resource
    JavaMailSender javaMailSender;

    @GetMapping("/send")
    public String send() {
        SimpleMailMessage message = new SimpleMailMessage();
        //设置邮件标题
        message.setSubject("警告邮件");
        //设置邮件内容
        message.setText("李同学您好，大清已亡了，没有朕了，当年的朕都是战犯！");
        //设置邮件发送给谁，可以多个，这里就发给你的QQ邮箱
        message.setTo("2480708091@qq.com");
        //邮件发送者，这里要与配置文件中的保持一致
        message.setFrom("jason_ma1982@qq.com");
        //OK，万事俱备只欠发送
        javaMailSender.send(message);
        return "success";
    }
}
